Let's move this discussion over to gnu-objc-runtime. As you'll notice, I've put that list in the To: line.
Regarding a missing method ( + initialize in your case) causing a failure:
In general, missing methods should cause forwarding behavior to be triggered. The Object class should implement a - forward metohd which gets called whenever a selector is sent to an object which does not respond to that selector. That method can then "do the right thing", for example, it can forward the message on to another object, or, it can signal an error.
The default implementation would probably look something like:
- forward:(SEL)aSelector <whatever other gnu-runtime parameters are relevant>
{
return [self doesNotImplement:aSelector <...>];
}
where doesNotImplement is also implemented by Object and might printf() a message or something like that.
This, btw, is taken largely from the NeXT and Smalltalk regimes.
Andrew Athan
Objective Technologies, Inc.
From: ssircar@canon.com (Subrata Sircar)
Date: Thu, 10 Sep 92 14:13:02 PDT
To: athan@object.com (Andrew C . Athan)
Subject: Re: NeXT objc extentions (Was: Your mission, should you choose to accept it. . .)
Cc: ObjC@canon.com
I wrote:
>Question: what happens if you declare x to be "SomeControllerClass
>*"? If the warning goes away then, I would be happier, since now
>you have told it what object x points to.
>[More generally, the compiler won't complain if you say id x =
>anObject; [x someMethod];. This is generally held to be a good
>thing for polymorphism. Do we want the same thing for protocols?]
athan@object.com (Andrew C . Athan) wrote:
! Neither one of these solves the problem. SomeControllerClass *x
! declares x to be a pointer to an instance of SomeControllerClass.
! What if x is pointing to a class object? i.e.
! x=[SomeControllerClass class];
Hmmm. Good question. What should happen? Should the compiler type-check and allow x to only respond to class messages? What is the declaration of x in this case?
> Actually, this also makes sense to me. The general question is:
> given an interface declaration, where should the implementation be?
> If you choose to allow it to be split up, then the compiler must
> not issue warnings when compiling the file, but must check back
> after all the files are compiled (in case the missing code has been
> added in a different file). NeXT essentially passed the buck on
> this question and required it to be in a single file.
! I was not clear. What you say is true, and I think it is reasonable not to
! do this sort of meta checking. However, there is no reason to get warnings
! when all the categories implementing all the protocol methods are in the
! same .m. That is the behavior I disliked. E.g.:
[Example deleted]
For clarity, the multiple implementations in a single file make sense. It should make code more readable, which is always a laudable goal :<)
However, doesn't that put us into the same situation? If the compiler doesn't find an method in the base implementation, what should it do?
Should it
a) flag an error
b) finish the current file and then check
c) finish the compile stage and then check
Currently, NeXT does a). I can make a case for c) but I'm not sure about b).
> However, for a given protocol which you write (and hence might be
> changed - I'm not terribly worried about the system protocols
> changing) you can add a version number method to the protocol, and
> require that implementers return the protocol version number as
> given in the header.
! This is an adequate solution, but it is not (IMHO) necessarily the nicest.
! Also, it does not address the problem that I can get a true return from
! conformsTo: and the class actually does not conformTo:!
I agree. Version control over protocols would be a good feature to add to the GNU Objective-C version of protocols, since we're still in the design stage.
- Subrata Sircar
ssircar@canon.com Canon Information Systems
Date: Thu, 10 Sep 92 17:07:41 -0500
From: jr@alpo.media.com (J.R. Jesson)
To: gnu-objc@prep.ai.mit.edu
Subject: Re: NeXT objc extentions (Was: Your mission, should you choose to accept it. . .)
Andrew Athan (athan@object.com) writes:
> [Previous discussion about @class, @protocol, etc.]
>
> There are other issues besides whether or not the
> compiler code will become available from NeXT. I
> personally feel that the @protocol extension has not
> been completely thought out by NeXT; I don't claim to know
> everything about it yet, nor do I claim to be doing
> everything right, but I feel certain pieces are
> missing/broken/not well thought out.
>
> To elaborate: Though I can only guess, I'd say that NeXT
> put in @protocol largely as support for their
> distributed objects paradigm (so an NXProxy can say,
> conformsTo:@protocol(SOMETHING) instead of
> isKindOf:[Something class]) .. much like they added
> keywords like "out," "in," and "inout." An @protocol
> (sometimes) builds a structure describing the methods;
> that structure is then tacked on to the Class object and
> can be used at runtime w/ distributed objects. This is all
> fine, as far as distributed objects go.
I think that NeXT put the protocol stuff for a couple of reasons.
First, it eliminates round-trips through the "wire" to do selector
validation and error reporting. I found this explanation in the NeXTSTEP PR2 release notes (DistributedObjects.rtf):
"...A client may specify the expected Protocol that an object will
serve upon the completion of a connection. Providing this
specification enables more efficient delivery of messages to remote
objects by avoiding a "discovery" message per method..."
It makes a big difference in the efficiency of sending
methods and the data associated with it across the wire. Ask any X
programmer about the evils of round trips to the X server. (Or ask a
naive X programmer why their apps run slowly - it could be because
they dont understand about server trips ;-) ).
I like protocols better than categories for doing things like
insuring that I've got all the methods needed to support delegate
operations. Again using NeXTSTEP as an example, my View classes
which do drag & drop declare the protocol <NXDraggingInfo> in the
@implementation directive. The compiler enforces the type and
existence of those methods without requiring that I put them
in an @interface clause of a superclass of the object I'm defining.
Again from the NeXT Literature (misspellings complements of NeXT):
"Protocols allow you to organize related method into groups that form
high-level behaviors. This gives library builders a tool to identifiy
sets of standard protocols, independent of the class hierarchy.
Protocols provide language support for the reuse of design (i.e.
interface), whereas classes support the reuse of code (i.e.
implementation). Well designed protocols can help users of an
application framework when learning or designing new classes."
[ Good complaints about protocols deleted... ]
> An additional problem that I see with @protocol is the
> question of versioning. Protocol checking is to some
> degree a compile-time event (and therefore versioning
> is not as important). @protocol is, however, often used
> as a run-time tool: it is possible to ask an object if it
> conforms to a protocol. Currently, I cannot attach a
> version number to a protocol. Because of this, if someone
> writes and compiles an object given the Controllers
> protocol above, and I then at a later time write code which
> does:
>
> if([someController
> conformsTo:@protocol(Controllers)])
>
> in the meantime, having changed the Controllers
> protocol, I am in trouble.
Yeah. I hadn't thought this issue through before now, but this
seems to be a lacking of the @protocol directive. Interestingly,
if you look at the file <objc/Protocol.h> you will find that
protocols are objects which are subclasses of the root object class:
@interface Protocol : Object
{
@private
[ private stuff deleted ]
}
@end
So, in the NeXT environment, it ought to be possible to attach a version number to the protocol using the NeXT factory method:
[ {aClass} setVersion: {anInt} ];
Of course the trick is finding the handle to the protocol "object".
Since versioning is only important when protocols are used in
distributed object messaging, what ought to happen is the proxy
object do a version validation when the connection is established
to a servicing process. Since this issue is a run-time support issue, and not a compilation issue, it seems sensible to say that @protocols
are Ok in concept but need help in implementation.
So, how does this discussion relate to gnu Objective-C? I think
we ought to improve protocols so that:
(1) we can find the handle to the protocol ( i.e. [ <protocolName> class ]
(2) the runtime is augmented so that version checking is